package remote_work.util;

import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import remote_work.dto.InputObject;
import remote_work.dto.OutputObject;

/**
 * @author LiuPing
 *
 * 2018年3月21日
 */
public class RequestService {

	private static Socket socket = null;
	private static ObjectOutputStream oos = null;
	private static ObjectInputStream ois = null;
	
	public static void main(String[] args) {
		File file = new File("D:\\000.jpg");
		InputObject inputObject = new InputObject();
		inputObject.setMethod("aaa");
		inputObject.addParams("file", file);
		OutputObject outputObject = execute(inputObject);
		System.out.println(outputObject);
	}
	
	public static OutputObject execute(InputObject inputObject) {
		try {
			socket = new Socket("127.0.0.1", 8080);
			oos = new ObjectOutputStream(socket.getOutputStream());
			oos.writeObject(inputObject);
			// 读取返回数据
			ois = new ObjectInputStream(socket.getInputStream());
			return (OutputObject) ois.readObject();
		} catch (IOException e) {
		} catch (ClassNotFoundException e) {
		} finally {
			try {
				socket.close();
			} catch (IOException e) {
				e.printStackTrace();
				
			}
		}
		return null;
	}
	
}
